package servlet;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import java.util.Set;
/*
    注册配置serlet的功能类
 */
public class MyRegister implements ServletContainerInitializer {
    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
        //完成servlet的创建和配置
        //1.创建servletDemo02的对象
        ServletDemo02 servletDemo02=new ServletDemo02();
        //2.在servletContext对象中添加servlet,并得到servlet的动态配置对象
        ServletRegistration.Dynamic registration = servletContext.addServlet("servletDemo02", servletDemo02);
        //3.配置servlet
        registration.addMapping("/servletDemo02");
        registration.setLoadOnStartup(1);//servlet加载时机
    }
}
